package com.star.uc.infras.config.sign;

import com.star.uc.infras.filter.RequestResponseLogFilter;
import com.star.uc.infras.filter.SignatureFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * 验签逻辑
 *
 * @author zhouhengzhe
 */
@Configuration
public class UcConfig {

    /**
     * 签名过滤器
     *
     * @param signatureFilter 签名过滤器
     * @return
     */
    @Bean
    public FilterRegistrationBean userSignCheckFilterReg(SignatureFilter signatureFilter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(signatureFilter);
        registration.addUrlPatterns("/user/*");
        registration.setName("SignatureFilter");
        registration.setOrder(Ordered.LOWEST_PRECEDENCE - 1);
        return registration;
    }

    /**
     * 请求响应日志,所有的接口都会过这里
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean accessLogFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new RequestResponseLogFilter());
        registration.addUrlPatterns("/**");
        registration.setName("AccessLogFilter");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }
}
